﻿@model TelecomGis.Models.UserModel.USERVM

@{  AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequest"
        //OnBegin = "opBeginProcess_Add_New_User"
    };
}

<script type="text/javascript">

    function opBeginProcess_Add_New_User() {

        var t = $('#Don_vi_on_add_user').combotree('getValues');	// get the tree object
        $("#listArrryToQLiId").val(t);

        makeloading('content_load_mast');
       

    }

    function completedAjaxRequest(obj) {

        var returnObj = eval('(' + obj.responseText + ')');

        if (returnObj.Status == "success") {

            $('#USER_TableContainer').datagrid({ url: _nameSubDomain + "/PhanQuyen/_USERList?donviId=" + $("#id_donvi_search_userManager").val() + "&tokt=" + $("#id_tokt_search_userManager").val() });

            $("#content_load_mast").unmask();

            close_window_elements('window_Edit_USER');

        } else {

            $("#content_load_mast").unmask();
            confirmOptionNormal(returnObj.Message);
        }

        return false;
    }

    $(document).ready(function () {

        $("#Don_vi_on_add_user").combotree({
            url: _nameSubDomain + "/Donvi_ToQL/Get_DonVi_To_OnJson_NotFindType_AndSetParent_All",
            idField: "id",
            treeField: "text",
            onSelect: function (row) {
                
            }

        });

        


    });

    function reLoad_Combox_In_List_Add_Donvi(id, pc) {

        $.get(_nameSubDomain + "/DONVI_NHANVIEN/ListDonviByByDonViAndPhanCap?donviid=" + id + "&phancap=" + pc, function (data) {

            var stringJson = jQuery.parseJSON(data);

            $('#to_on_trung_tam_add_donvi_user')
                        .find('option')
                        .remove();

            if ($('#list_nedd_on_trung_tam_add_donvi_user option').length == 0) {

                if (stringJson.length > 0) {

                    for (var i = 0 ; i < stringJson.length; i++) {

                        $('#to_on_trung_tam_add_donvi_user')
                            .append($('<option></option>').attr('ttqlId', id).val(stringJson[i].DONVIID).html(stringJson[i].TEN));
                    }
                }
            }
            else {

                if (stringJson.length > 0) {

                    for (var i = 0 ; i < stringJson.length; i++) {

                        var optionFindToAdd = $('#list_nedd_on_trung_tam_add_donvi_user  option[value="' + stringJson[i].DONVIID + '"]');
                        if (optionFindToAdd.length > 0) {
                            // đã có rùi nên ko add
                            //to do
                        }
                        else {

                            $('#to_on_trung_tam_add_donvi_user')
                                .append($('<option></option>').attr('ttqlId', id).val(stringJson[i].DONVIID).html(stringJson[i].TEN));
                        }
                    }
                }



            }

        });
    }

    function reload_thong_tin_don_vi_add(capduoiId) {

        var DonviCaoNhat = Get_don_vi_by_by_cap_duoi(capduoiId);
        reLoad_Combox_In_List_Add_Donvi(DonviCaoNhat.DONVIID, 3);
        $("#trung_tan_ql_on_add_user").combobox('setValue', DonviCaoNhat.DONVIID);

    }

</script>

@using (Ajax.BeginForm("AddNhanVien", "PhanQuyen", null, ajaxOpts, new { enctype = "multipart/form-data" }))
{
    @Html.HiddenFor(model => model._entityUser.USERID)
    <input type="hidden" id="donviid_hientai_checkjuqery" name="donviid_hientai_checkjuqery" value="" />
    <input type="hidden" id="toktid_hientai_checkjuqery" name="toktid_hientai_checkjuqery" value="" />
    @Html.HiddenFor(model => model.listArrryDonviId)
    @Html.HiddenFor(model => model.listArrryToQLiId)
    <div id="content_load_mast">
        <div class="easyui-layout" id="Layout_add_new_user_win_dow" style="width: 710px; height: 530px">
            <div data-options="region:'north'" title="Thông tin User Site" style="height: 330px">
                <table class="css_table_form">
                    <tr>
                        <td style="width:400px">
                            <table class="css_table_form">

                                <tr>
                                    <td>Đơn vị - tổ:</td>
                                </tr>
                                <tr>
                                    <td>
                                        <input  class="easyui-combotree" multiple  value="@ViewBag.ToKyThucatAddUser" id="Don_vi_on_add_user" style="width: 258px;"></td>
                                </tr>
                                <tr>
                                    <td>Tên đăng nhập:</td>
                                </tr>
                                <tr>
                                    <td>@Html.TextBoxFor(model => model._entityUser.USERNAME, new { id = "USERNAME_MASONV", @style = "text-transform: uppercase;", @class = "txt_use_page; " })</td>
                                </tr>
                                <tr>
                                    <td>Mật khẩu:</td>
                                </tr>
                                <tr>
                                    <td>@Html.PasswordFor(model => model._entityUser.PASSWORD, new { @class = "txt_use_page" })</td>
                                </tr>
                                <tr>
                                    <td>Họ tên:</td>
                                </tr>
                                <tr>
                                    <td>
                                       @Html.TextBoxFor(model => model._entityUser.HOTEN, new { @class = "txt_use_page" })</td>
                                </tr>
                                <tr>
                                    <td>Active:</td>
                                </tr>
                                <tr>
                                    <td>@Html.EditorFor(model => model._entityUser.ACTIVE)</td>
                                </tr>

                            </table>
                        </td>
                        <td>

                            <table class="css_table_form">
                                @for (var i = 0; i < Model._LoaiSiteOnUser.Count(); i++)
                                {
                                    <tr>
                                        <td style="width:140px">
                                            @Html.HiddenFor(it => it._LoaiSiteOnUser[i].Id)
                                            <label>@Model._LoaiSiteOnUser[i].Name</label>
                                        </td>
                                        <td>
                                            @Html.CheckBoxFor(it => it._LoaiSiteOnUser[i].Checkbox)
                                        </td>
                                    </tr>
                                }
                            </table>

                        </td>
                    </tr>

                </table>
            </div>
            <div data-options="region:'west', collapsible:false" title="Thông tin Roles" style="width: 350px; height: 120px; padding: 10px">
                <table class="css_table_form">
                    @for (var i = 0; i < Model._RolesOnUser.Count(); i++)
                    {
                        <tr>
                            <td>
                                @Html.HiddenFor(it => it._RolesOnUser[i].Id)
                                <label>@Model._RolesOnUser[i].Name</label>
                            </td>
                            <td>
                                @Html.CheckBoxFor(it => it._RolesOnUser[i].Checkbox)
                            </td>
                        </tr>
                    }
                </table>

            </div>
            <div data-options="region:'center'" title="Thông tin Quyền Hệ Thống" style="width: 350px; height: 150px; padding: 10px">
                <table class="css_table_form">
                    @for (var i = 0; i < Model._QUYENHTOnUser.Count(); i++)
                    {
                        <tr>
                            <td>
                                @Html.HiddenFor(it => it._QUYENHTOnUser[i].Id)
                                <label>@Model._QUYENHTOnUser[i].Name</label>
                            </td>
                            <td>
                                @Html.CheckBoxFor(it => it._QUYENHTOnUser[i].Checkbox)
                            </td>
                        </tr>
                    }
                </table>

            </div>
            
        </div>
        <div class="footer_submit" style="margin-top: 10px; text-align: center">
            <button type="submit" onclick="return opBeginProcess_Add_New_User(); " class="k-button-custom" data-role="button" role="button" aria-disabled="false" tabindex="0">
                <span class="k-sprite k-icon k-edit"></span>Cập nhật</button>
            <button type="button" onclick="return close_window_elements('window_Edit_USER');" class="k-button-custom" data-role="button" role="button" aria-disabled="false" tabindex="0">
                <span class="k-icon k-i-close"></span>Hủy bỏ</button>
        </div>
    </div>
}
